﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Work02_P1.Mapper;
using Work02_P1.Pojo;

namespace Work02_P1
{
    public partial class ChangePassword : Form
    {
        public ChangePassword()
        {
            InitializeComponent();
            this.ControlBox = false;

        }
        Form1 login = null;
        public ChangePassword(Form1 login)
        {
            this.login = login;
            InitializeComponent();
            this.ControlBox = false;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            backToLogin();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }
        private void backToLogin()
        {
            login.Show();
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string userId = textBox2.Text;
            string passWord = textBox4.Text;
            string phoneNumber = textBox3.Text;

            if (userId.Equals("") ||  passWord.Equals("") || phoneNumber.Equals(""))
            {
                MessageBox.Show("您有信息没有填写！\n所有信息都要填写！");
                return;
            }

            if (passWord.Length < 8 || passWord.Length > 20)
            {
                MessageBox.Show("填写的密码不能少于8位且不能多于20位！");
                return;

            }

            if (phoneNumber.Length < 11 || phoneNumber.Length > 11)
            {
                MessageBox.Show("您填写的电话号码格式错误！！");
            }
            else
            {
                foreach (char now in phoneNumber)
                {
                    if (now > '9' || now < '0')
                    {
                        MessageBox.Show("您填写的电话号码中存在非法字符！");
                        return;
                    }
                }
            }


         
                bool res = UserMapper.updatePassword(new userInfo(userId, "", passWord, 0, phoneNumber));
                if (res)
                {
                    MessageBox.Show("修改成功！");
                    backToLogin();

                }
                else MessageBox.Show("账号或密保手机填写错误！");
            
        }
    }
}
